/*package com.sxc.oa.web.action;

import com.sxc.oa.utils.DButil;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DepListServlet extends HttpServlet {



    protected void doGet() throws IOException {
        doGet(null, null);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String contextPath = request.getContextPath();
        //设置响应的内容类型以及字符集，防止中文乱码问题。

        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        out.print("<!DOCTYPE html>");
        out.print("<html lang='en'>");
        out.print("<head>");
        out.print("<meta charset='UTF-8'>");
        out.print("<meta name='viewport' content='width=device-width, initial-scale=1.0'>");
        out.print("<title>部门列表页面</title>");

        out.print("<script type='text/javascript'>");
        out.print("        function del(dno){");
        out.print("    if(window.confirm('删除不可恢复')){");
        out.print("        document.location.href = "+contextPath+"'/oa/dept/delete?deptno='+dno");
        out.print("    }");
        out.print("}");
        out.print("</script>");

        out.print("</head>");
        out.print("<body>");
        out.print("<h1 align='center'>部门列表</h1>");
        out.print("<hr>");
        out.print("<table border='1px' align='center' width='50%'>");
        out.print("<tr>");
        out.print("<th>序号</th>");
        out.print("<th>部门编号</th>");
        out.print("<th>部门名称</th>");
        out.print("<th>操作</th>");
        out.print("</tr>");
        //以上部分是不动的

        //连接数据库，查询所有的部门
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        DButil Dbutil = null;
        try {
            // 获取链接
            conn = Dbutil.getConnction();
            // 获取预编译的数据库操作对象
            String sql = "select deptno as a,dname,loc from dept";
            ps = conn.prepareStatement(sql);
            // 执行SQL语句
            rs = ps.executeQuery();
            int i = 0;
            while (rs.next()) {
                String deptno = rs.getString("a");
                String dname = rs.getString("dname");
                String loc = rs.getString("loc");
                out.print("--------------");
                out.print("<tr>");
                out.print("<td>"+(++i)+"</td>");
                out.print("<td>"+deptno+"</td>");
                out.print("<td>"+dname+"</td>");
                out.print("<td>"+loc+"</td>");
                out.print("<td>");
                out.print("<a href='javascript:void(0)' onclick='del("+deptno+")'>delete</a>");
                out.print("<a href='edit.html'>change</a>");
                out.print("<a href='"+contextPath+"/dept/detail?deptno="+deptno+"'>detail</a>  ");
                out.print("</td>");
                out.print("</tr>");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            // 关闭资源
            try {
                Dbutil.close(conn, ps, rs);
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }

    }

}
*/
/*package com.sxc.oa.web.action;

import com.sxc.oa.utils.DButil;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DepListServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request , HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String contextPath = request.getContextPath();
        //设置响应的内容类型以及字符集，防止中文乱码问题。
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        out.print("<!DOCTYPE html>");
        out.print("<html lang='en'>");
        out.print("<head>");
        out.print("<meta charset='UTF-8'>");
        out.print("<meta name='viewport' content='width=device-width, initial-scale=1.0'>");
        out.print("<title>部门列表页面</title>");
        out.print("<script type='text/javascript'>");
        out.print("function del(dno) {");
        out.print("    if(window.confirm('删除不可恢复')) {");
        out.print("        document.location.href = '" + contextPath + "/dept/delete?deptno=' + dno;");
        out.print("    }");
        out.print("}");
        out.print("</script>");
        out.print("</head>");
        out.print("<body>");
        out.print("<h1 align='center'>部门列表</h1>");
        out.print("<hr>");
        out.print("<table border='1px' align='center' width='50%'>");
        out.print("<tr>");
       // out.print("<th>序号</th>");
        out.print("<th>部门编号</th>");
        out.print("<th>部门名称</th>");
        out.print("<th>地点</th>");
        out.print("<th>操作</th>");
        out.print("</tr>");

        //连接数据库，查询所有的部门
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            // 获取链接
            conn = DButil.getConnction();
            // 获取预编译的数据库操作对象
            String sql = "select deptno, dname, loc from dept";
            ps = conn.prepareStatement(sql);
            // 执行SQL语句
            rs = ps.executeQuery();
           // int i = 0;
            while (rs.next()) {
                String deptno = rs.getString("deptno");
                String dname = rs.getString("dname");
                String loc = rs.getString("loc");
                out.print("<tr>");
                //out.print("<td>" + (++i) + "</td>");
                out.print("<td>" + deptno + "</td>");
                out.print("<td>" + dname + "</td>");
                out.print("<td>" + loc + "</td>");
                out.print("<td>");
                out.print("<a href='javascript:void(0)' onclick='del(" + deptno + ")'>delete</a>");
                out.print("<a href='"+contextPath+"/dept/edit?deptno="+deptno+"'>change</a>");
                out.print("<a href='" + contextPath + "/dept/detail?deptno=" + deptno + "'>detail</a>");
                out.print("</td>");
                out.print("</tr>");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            // 关闭资源
            try {
                DButil.close(conn, ps, rs);
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }

        out.print("</table>");
        out.print("<hr>");
        out.print("<a href='"+contextPath+"/add.html'>新增部门</a>");
        out.print("</body>");
        out.print("</html>");
    }
}*/
/*package com.sxc.oa.web.action;

import com.sxc.oa.utils.DButil;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DepListServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String contextPath = request.getContextPath();
        //设置响应的内容类型以及字符集，防止中文乱码问题。
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        out.print("<!DOCTYPE html>");
        out.print("<html lang='en'>");
        out.print("<head>");
        out.print("<meta charset='UTF-8'>");
        out.print("<meta name='viewport' content='width=device-width, initial-scale=1.0'>");
        out.print("<title>部门列表页面</title>");
        out.print("<script type='text/javascript'>");
        out.print("function del(dno) {");
        out.print("    if(window.confirm('删除不可恢复')) {");
        out.print("        document.location.href = '" + contextPath + "/dept/delete?deptno=' + dno;");
        out.print("    }");
        out.print("}");
        out.print("</script>");
        out.print("</head>");
        out.print("<body>");
        out.print("<h1 align='center'>部门列表</h1>");
        out.print("<hr>");
        out.print("<table border='1px' align='center' width='50%'>");
        out.print("<tr>");
        // out.print("<th>序号</th>");
        out.print("<th>部门编号</th>");
        out.print("<th>部门名称</th>");
        out.print("<th>地点</th>");
        out.print("<th>操作</th>");
        out.print("</tr>");

        //连接数据库，查询所有的部门
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            // 获取链接
            conn = DButil.getConnction();
            // 获取预编译的数据库操作对象
            String sql = "select deptno, dname, loc from dept";
            ps = conn.prepareStatement(sql);
            // 执行SQL语句
            rs = ps.executeQuery();
            // int i = 0;
            while (rs.next()) {
                String deptno = rs.getString("deptno");
                String dname = rs.getString("dname");
                String loc = rs.getString("loc");
                out.print("<tr>");
                //out.print("<td>" + (++i) + "</td>");
                out.print("<td>" + deptno + "</td>");
                out.print("<td>" + dname + "</td>");
                out.print("<td>" + loc + "</td>");
                out.print("<td>");
                out.print("<a href='javascript:void(0)' onclick='del(" + deptno + ")'>delete</a> ");
                out.print("<a href='" + contextPath + "/dept/edit?deptno=" + deptno + "'>change</a> ");
                out.print("<a href='" + contextPath + "/dept/detail?deptno=" + deptno + "'>detail</a>");
                out.print("</td>");
                out.print("</tr>");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            // 关闭资源
            try {
                DButil.close(conn, ps, rs);
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }

        out.print("</table>");
        out.print("<hr>");
        out.print("<a href='" + contextPath + "/add.html'>新增部门</a> ");
        out.print("<a href='" + contextPath + "/addMember.html'>新增成员</a>");
        out.print("</body>");
        out.print("</html>");
    }
}*/
/*package com.sxc.oa.web.action;

import com.sxc.oa.utils.DButil;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DepListServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String contextPath = request.getContextPath();
        //设置响应的内容类型以及字符集，防止中文乱码问题。
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        out.print("<!DOCTYPE html>");
        out.print("<html lang='en'>");
        out.print("<head>");
        out.print("<meta charset='UTF-8'>");
        out.print("<meta name='viewport' content='width=device-width, initial-scale=1.0'>");
        out.print("<title>部门列表页面</title>");
        out.print("<script type='text/javascript'>");
        out.print("function del(dno) {");
        out.print("    if(window.confirm('删除不可恢复')) {");
        out.print("        document.location.href = '" + contextPath + "/dept/delete?deptno=' + dno;");
        out.print("    }");
        out.print("}");
        out.print("function delMember() {");
        out.print("    const memberId = document.getElementById('memberId').value;");
        out.print("    const memberName = document.getElementById('memberName').value;");
        out.print("    const memberZhuanye = document.getElementById('memberZhuanye').value;");
        out.print("    if(memberId && memberName && memberZhuanye) {");
        out.print("        if(window.confirm('确认删除该成员吗？')) {");
        out.print("            document.location.href = '" + contextPath + "/member/delete?id=' + memberId + '&name=' + memberName + '&zhuanye=' + memberZhuanye;");
        out.print("        }");
        out.print("    } else {");
        out.print("        alert('请输入完整的成员信息！');");
        out.print("    }");
        out.print("}");
        out.print("</script>");
        out.print("</head>");
        out.print("<body>");
        out.print("<h1 align='center'>部门列表</h1>");
        out.print("<hr>");
        out.print("<table border='1px' align='center' width='50%'>");
        out.print("<tr>");
        // out.print("<th>序号</th>");
        out.print("<th>部门编号</th>");
        out.print("<th>部门名称</th>");
        out.print("<th>地点</th>");
        out.print("<th>操作</th>");
        out.print("</tr>");

        //连接数据库，查询所有的部门
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            // 获取链接
            conn = DButil.getConnction();
            // 获取预编译的数据库操作对象
            String sql = "select deptno, dname, loc from dept";
            ps = conn.prepareStatement(sql);
            // 执行SQL语句
            rs = ps.executeQuery();
            // int i = 0;
            while (rs.next()) {
                String deptno = rs.getString("deptno");
                String dname = rs.getString("dname");
                String loc = rs.getString("loc");
                out.print("<tr>");
                //out.print("<td>" + (++i) + "</td>");
                out.print("<td>" + deptno + "</td>");
                out.print("<td>" + dname + "</td>");
                out.print("<td>" + loc + "</td>");
                out.print("<td>");
                out.print("<a href='javascript:void(0)' onclick='del(" + deptno + ")'>delete</a> ");
                out.print("<a href='" + contextPath + "/dept/edit?deptno=" + deptno + "'>change</a> ");
                out.print("<a href='" + contextPath + "/dept/detail?deptno=" + deptno + "'>detail</a>");
                out.print("</td>");
                out.print("</tr>");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            // 关闭资源
            try {
                DButil.close(conn, ps, rs);
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }

        out.print("</table>");
        out.print("<hr>");
        out.print("<a href='" + contextPath + "/add.html'>新增部门</a> ");
        out.print("<a href='" + contextPath + "/addMember.html'>新增成员</a>");
        out.print("<hr>");
        out.print("<h2>删除成员</h2>");
        out.print("<form>");
        out.print("成员ID: <input type='text' id='memberId' name='id'><br>");
        out.print("成员姓名: <input type='text' id='memberName' name='name'><br>");
        out.print("成员专业: <input type='text' id='memberZhuanye' name='zhuanye'><br>");
        out.print("<input type='button' value='删除成员' onclick='delMember()'>");
        out.print("</form>");
        out.print("</body>");
        out.print("</html>");
    }
}*/
package com.sxc.oa.web.action;

import com.sxc.oa.utils.DButil;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DepListServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String contextPath = request.getContextPath();
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        out.print("<!DOCTYPE html>");
        out.print("<html lang='en'>");
        out.print("<head>");
        out.print("<meta charset='UTF-8'>");
        out.print("<meta name='viewport' content='width=device-width, initial-scale=1.0'>");
        out.print("<title>部门列表页面</title>");
        out.print("<script type='text/javascript'>");
        out.print("function del(dno) {");
        out.print("    if(window.confirm('删除不可恢复')) {");
        out.print("        document.location.href = '" + contextPath + "/dept/delete?deptno=' + dno;");
        out.print("    }");
        out.print("}");
        out.print("</script>");
        out.print("</head>");
        out.print("<body>");
        out.print("<h1 align='center'>部门列表</h1>");
        out.print("<hr>");
        out.print("<table border='1px' align='center' width='50%'>");
        out.print("<tr>");
        out.print("<th>部门编号</th>");
        out.print("<th>部门名称</th>");
        out.print("<th>地点</th>");
        out.print("<th>操作</th>");
        out.print("</tr>");

        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            conn = DButil.getConnction();
            String sql = "select deptno, dname, loc from dept";
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            while (rs.next()) {
                String deptno = rs.getString("deptno");
                String dname = rs.getString("dname");
                String loc = rs.getString("loc");
                out.print("<tr>");
                out.print("<td>" + deptno + "</td>");
                out.print("<td>" + dname + "</td>");
                out.print("<td>" + loc + "</td>");
                out.print("<td>");
                out.print("<a href='javascript:void(0)' onclick='del(" + deptno + ")'>delete</a> ");
                out.print("<a href='" + contextPath + "/dept/edit?deptno=" + deptno + "'>change</a> ");
                out.print("<a href='" + contextPath + "/dept/detail?deptno=" + deptno + "'>detail</a>");
                out.print("</td>");
                out.print("</tr>");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                DButil.close(conn, ps, rs);
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }

        out.print("</table>");
        out.print("<hr>");
        out.print("<div style='text-align: center;'>");
        out.print("<a href='" + contextPath + "/add.html'>新增部门</a> ");
        out.print("<a href='" + contextPath + "/addMember.html'>新增成员</a> ");
        out.print("<a href='" + contextPath + "/deleteMember.html'>删除成员</a> ");
        out.print("<a href='" + contextPath + "/queryMember.html'>查询成员</a>");
        out.print("</div>");
        out.print("</body>");
        out.print("</html>");
    }
}